import request from "@/utils/request";
//获取文件
export function getImgUrl(path) {
   return `http://localhost:9999/api/files/get/${path}`
    // return `http://47.107.171.173:8088/api/files/get/${path}`
}

//上传单个文件，会返回文件路径（包含新文件名）
export function uploadFile(file,path) {
    const formData = new FormData();
    formData.append('file', file);
    formData.append('path',path);
    return request({
      url: '/files/upload',
      method: 'post',
      data: formData
    })
  }

// 批量上传文件：/files/batchUpload
// files: File 数组，path: 目标目录
// 后端返回文件路径数组，此处直接返回 request Promise
export function batchUploadFiles(files, path) {
    const formData = new FormData();
    files.forEach(file => {
        formData.append('files', file);
    });
    formData.append('path', path);
    return request({
        url: '/files/batchUpload',
        method: 'post',
        data: formData
    });
}

//批量删除文件：/files/batchDelete
//paths: 文件路径数组
export function batchRemoveFiles(paths) {
    return request({
        url: '/files/batchDelete',
        method: 'post',
        data: paths
    });
}